/********************************************************************
FileName    :   Dal_TempStorageH.cs
CreateTime  :   2019-01-17 01:01
BaseClass   :   Dal_TempStorageH
FileType    :   .cs
Author      :  minjie
Description :   Dal_TempStorageHDAL层（简单三层）
*********************************************************************/

using System;
using System.Text;
using System.Data.SqlClient;
using System.Collections.Generic;

using System.Data;
using HT.DBUtility;

namespace HT.DAL
{
	/// <summary>
	/// Dal_TempStorageH的摘要说明。
	/// </summary>
	public partial class Dal_TempStorageH 
  	{ 
     		      
  		public bool Exists() 
  		{ 
  			StringBuilder strSql=new StringBuilder(); 
  			strSql.Append("select count(1) from TempStorageH"); 
           SqlParameter[] parameters = { };  
          			return DbHelperSQL.Exists(strSql.ToString(),parameters); 
  		} 
  		 
  				 
  		 
  		/// <summary> 
  		/// 增加一条数据 
  		/// </summary> 
  		public  bool  Add(TempStorageH_Entity model) 
  		{ 
  			StringBuilder strSql=new StringBuilder(); 
  			strSql.Append("insert into TempStorageH(");			 
  	        strSql.Append("tempDjh,Khbh,Khmc,Yyybh,Yyymc,Sl,Je,temptime) values ("); 
  	        strSql.Append("	@tempDjh,@Khbh,@Khmc,@Yyybh,@Yyymc,@Sl,@Je,@temptime	 ) "); 
  			SqlParameter[] parameters = { 
              new SqlParameter("@tempDjh", SqlDbType.Int,4) ,              
              new SqlParameter("@Khbh", SqlDbType.VarChar,50) ,              
              new SqlParameter("@Khmc", SqlDbType.VarChar,50) ,              
              new SqlParameter("@Yyybh", SqlDbType.VarChar,50) ,              
              new SqlParameter("@Yyymc", SqlDbType.VarChar,50) ,              
              new SqlParameter("@Sl", SqlDbType.Int,4) ,              
              new SqlParameter("@Je", SqlDbType.Decimal,9) ,              
              new SqlParameter("@temptime", SqlDbType.DateTime)};             
              parameters[0].Value = model.tempDjh;  
              
           if (model.Khbh != null)  
              parameters[1].Value = model.Khbh;  
           else  
              parameters[1].Value = DBNull.Value;  
              
           if (model.Khmc != null)  
              parameters[2].Value = model.Khmc;  
           else  
              parameters[2].Value = DBNull.Value;  
              
           if (model.Yyybh != null)  
              parameters[3].Value = model.Yyybh;  
           else  
              parameters[3].Value = DBNull.Value;  
              
           if (model.Yyymc != null)  
              parameters[4].Value = model.Yyymc;  
           else  
              parameters[4].Value = DBNull.Value;  
              
              parameters[5].Value = model.Sl;  
              
           if (model.Je != null)  
              parameters[6].Value = model.Je;  
           else  
              parameters[6].Value = DBNull.Value;  
              
           if (model.temptime != null)  
              parameters[7].Value = model.temptime;  
           else  
              parameters[7].Value = DBNull.Value;  
              
  			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);			 
  			if (rows > 0) 
  			{ 
  				return true; 
  			} 
  			else 
  			{ 
              return false;; 
           }  
  		} 
  		 
  		/// <summary> 
  		/// 增加一条数据(字符串) 
  		/// </summary> 
  		public  string  AddStr(TempStorageH_Entity model) 
  		{ 
  				if(model.tempDjh==null) 
  				{ 
  					model.tempDjh=0; 
  				} 
  				if(model.Khbh==null) 
  				{ 
  					model.Khbh="";  
  				} 
  				if(model.Khmc==null) 
  				{ 
  					model.Khmc="";  
  				} 
  				if(model.Yyybh==null) 
  				{ 
  					model.Yyybh="";  
  				} 
  				if(model.Yyymc==null) 
  				{ 
  					model.Yyymc="";  
  				} 
  				if(model.Sl==null) 
  				{ 
  					model.Sl=0; 
  				} 
  				if(model.Je==null) 
  				{ 
  					model.Je=0; 
  				} 
  		 
  			StringBuilder strSql=new StringBuilder(); 
  			strSql.Append("insert into TempStorageH(");			 
  	        strSql.Append("tempDjh,Khbh,Khmc,Yyybh,Yyymc,Sl,Je,temptime) values ("); 
  	        strSql.Append("	"+ model.tempDjh+",'"+ model.Khbh+"','"+ model.Khmc+"','"+ model.Yyybh+"','"+ model.Yyymc+"',"+ model.Sl+","+ model.Je+",'" +model.temptime+"'	 ) "); 
           return strSql.ToString(); 
  		} 
  		 
  		 
  		/// <summary> 
  		/// 更新一条数据 
  		/// </summary> 
  		public bool Update(TempStorageH_Entity model) 
  		{ 
  			StringBuilder strSql=new StringBuilder(); 
  			strSql.Append("update TempStorageH set "); 
                      strSql.Append(" tempDjh = @tempDjh,"); 
              strSql.Append(" Khbh = @Khbh,"); 
              strSql.Append(" Khmc = @Khmc,"); 
              strSql.Append(" Yyybh = @Yyybh,"); 
              strSql.Append(" Yyymc = @Yyymc,"); 
              strSql.Append(" Sl = @Sl,"); 
              strSql.Append(" Je = @Je,"); 
              strSql.Append(" temptime = @temptime"); 
  			strSql.Append(" where   "); 
  						 
           SqlParameter[] parameters = { 
                      new SqlParameter("@tempDjh", SqlDbType.Int,4) ,              
              new SqlParameter("@Khbh", SqlDbType.VarChar,50) ,              
              new SqlParameter("@Khmc", SqlDbType.VarChar,50) ,              
              new SqlParameter("@Yyybh", SqlDbType.VarChar,50) ,              
              new SqlParameter("@Yyymc", SqlDbType.VarChar,50) ,              
              new SqlParameter("@Sl", SqlDbType.Int,4) ,              
              new SqlParameter("@Je", SqlDbType.Decimal,9) ,              
              new SqlParameter("@temptime", SqlDbType.DateTime)};             
                   if (model.tempDjh != null)  
              parameters[0].Value = model.tempDjh;  
           else  
              parameters[0].Value = DBNull.Value;  
              
           if (model.Khbh != null)  
              parameters[1].Value = model.Khbh;  
           else  
              parameters[1].Value = DBNull.Value;  
              
           if (model.Khmc != null)  
              parameters[2].Value = model.Khmc;  
           else  
              parameters[2].Value = DBNull.Value;  
              
           if (model.Yyybh != null)  
              parameters[3].Value = model.Yyybh;  
           else  
              parameters[3].Value = DBNull.Value;  
              
           if (model.Yyymc != null)  
              parameters[4].Value = model.Yyymc;  
           else  
              parameters[4].Value = DBNull.Value;  
              
           if (model.Sl != null)  
              parameters[5].Value = model.Sl;  
           else  
              parameters[5].Value = DBNull.Value;  
              
           if (model.Je != null)  
              parameters[6].Value = model.Je;  
           else  
              parameters[6].Value = DBNull.Value;  
              
           if (model.temptime != null)  
              parameters[7].Value = model.temptime;  
           else  
              parameters[7].Value = DBNull.Value;  
              
           int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters); 
  			if (rows > 0) 
  			{ 
  				return true; 
  			} 
  			else 
  			{ 
  				return false; 
  			} 
  		} 
  		 
  		 
  		/// <summary> 
  		/// 更新一条数据(字符串) 2016-07-13更新 
  		///   2017-03-23更新 minjie 
  		/// </summary> 
  		public  string  UpdateStr(TempStorageH_Entity model) 
  		{ 
  				if(model.tempDjh==null) 
  				{ 
  					model.tempDjh=0; 
  				} 
  				if(model.Khbh==null) 
  				{ 
  					model.Khbh="";  
  				} 
  				if(model.Khmc==null) 
  				{ 
  					model.Khmc="";  
  				} 
  				if(model.Yyybh==null) 
  				{ 
  					model.Yyybh="";  
  				} 
  				if(model.Yyymc==null) 
  				{ 
  					model.Yyymc="";  
  				} 
  				if(model.Sl==null) 
  				{ 
  					model.Sl=0; 
  				} 
  				if(model.Je==null) 
  				{ 
  					model.Je=0; 
  				} 
  			StringBuilder strSql=new StringBuilder(); 
  			strSql.Append("update TempStorageH set "); 
              strSql.Append(" tempDjh = "+model.tempDjh+","); 
              strSql.Append(" Khbh ='"+ model.Khbh+"',"); 
              strSql.Append(" Khmc ='"+ model.Khmc+"',"); 
              strSql.Append(" Yyybh ='"+ model.Yyybh+"',"); 
              strSql.Append(" Yyymc ='"+ model.Yyymc+"',"); 
              strSql.Append(" Sl = "+model.Sl+","); 
              strSql.Append(" Je = "+model.Je+","); 
              strSql.Append(" temptime =' "+model.temptime+"'"); 
  			strSql.Append(" where   "); 
  						 
           return strSql.ToString(); 
  		} 
  		 
  		 
  		/// <summary> 
  		/// 删除一条数据 
  		/// </summary> 
  		public bool Delete() 
  		{ 
  			 
  			StringBuilder strSql=new StringBuilder(); 
  			strSql.Append("delete from TempStorageH "); 
  			strSql.Append(" where  "); 
           SqlParameter[] parameters = { };  
  			 
   
  			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters); 
  			if (rows > 0) 
  			{ 
  				return true; 
  			} 
  			else 
  			{ 
  				return false; 
  			} 
  		} 
  		 
  		/// <summary> 
  		/// 批量删除一批数据 
  		/// </summary> 
  		public bool DeleteList(string lists ) 
  		{ 
  			StringBuilder strSql=new StringBuilder(); 
  			strSql.Append("delete from TempStorageH "); 
  			strSql.Append(" where ID in ("+ lists + ")  "); 
  			int rows=DbHelperSQL.ExecuteSql(strSql.ToString()); 
  			if (rows > 0) 
  			{ 
  				return true; 
  			} 
  			else 
  			{ 
  				return false; 
  			} 
  		} 
  		 
  		 
  		/// <summary> 
  		/// 得到一个对象实体 
  		/// </summary> 
  		public TempStorageH_Entity GetModel() 
  		{ 
  			 
  			StringBuilder strSql=new StringBuilder(); 
  			strSql.Append("select  tempDjh,Khbh,Khmc,Yyybh,Yyymc,Sl,Je,temptime");			 
  	        strSql.Append("  from TempStorageH"); 
  			strSql.Append(" where   "); 
           SqlParameter[] parameters = { };  
  			 
  			 
  			TempStorageH_Entity model=new TempStorageH_Entity(); 
  			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters); 
  		        DataTable dt=ds.Tables[0];	  
  				return DataTableToEntity(dt); 
  		} 
  		 
  		 
  		 
  		 
  		/// <summary> 
  		/// 将数据集(DataTable)转换 对象 TempStorageH_Entity
  		/// 创建人：minjie 
  		/// 创建时间:2019-01-17 01:45:08 
  		/// </summary> 
  		public TempStorageH_Entity DataTableToEntity(DataTable dt) 
  		{ 
  			TempStorageH_Entity model=new TempStorageH_Entity(); 
  			 
  			if(dt!=null&&dt.Rows.Count>0) 
  			{ 
  				if(dt.Rows[0]["tempDjh"]!=null&&dt.Rows[0]["tempDjh"].ToString()!="") 
  				{ 
  					model.tempDjh=int.Parse(dt.Rows[0]["tempDjh"].ToString()); 
  				} 
  				model.Khbh= dt.Rows[0]["Khbh"].ToString(); 
  				model.Khmc= dt.Rows[0]["Khmc"].ToString(); 
  				model.Yyybh= dt.Rows[0]["Yyybh"].ToString(); 
  				model.Yyymc= dt.Rows[0]["Yyymc"].ToString(); 
  				if(dt.Rows[0]["Sl"]!=null&&dt.Rows[0]["Sl"].ToString()!="") 
  				{ 
  					model.Sl=int.Parse(dt.Rows[0]["Sl"].ToString()); 
  				} 
  				if(dt.Rows[0]["Je"]!=null&&dt.Rows[0]["Je"].ToString()!="") 
  				{ 
  					model.Je=decimal.Parse(dt.Rows[0]["Je"].ToString()); 
  				} 
  				if(dt.Rows[0]["temptime"]!=null&&dt.Rows[0]["temptime"].ToString()!="") 
  				{ 
  					model.temptime=DateTime.Parse(dt.Rows[0]["temptime"].ToString()); 
  				} 
  				return model; 
  			} 
  			else 
  			{ 
  				return null; 
  			} 
  		} 
  		 
  		/// <summary> 
  		/// 分页获取数据列表 
  		/// </summary> 
  		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex) 
  		{ 
  			StringBuilder strSql=new StringBuilder(); 
  		 strSql.Append("SELECT * FROM ( "); 
  		 strSql.Append(" SELECT ROW_NUMBER() OVER ("); 
  if (!string.IsNullOrEmpty(orderby.Trim())) 
 { 
    strSql.Append("order by " ); 
 } 
else  
 { 
     strSql.Append("order by  desc"); 
 } 
		 strSql.Append(")AS Row, T.*  from TempStorageH T "); 
  		 if (!string.IsNullOrEmpty(strWhere.Trim()))  
  			{ 
  			 strSql.Append(" WHERE " + strWhere); 
  			} 
  		    strSql.Append(" ) TT"); 
  	        strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);			return DbHelperSQL.Query(strSql.ToString()); 
  		} 
  		 
  		 
  		/// <summary> 
  		/// 获得数据列表 
  		/// </summary> 
  		public DataSet GetList(string strWhere) 
  		{ 
  			StringBuilder strSql=new StringBuilder(); 
  			strSql.Append("select * "); 
  			strSql.Append(" FROM TempStorageH "); 
  			if(strWhere.Trim()!="") 
  			{ 
  				strSql.Append(" where "+strWhere); 
  			} 
  			return DbHelperSQL.Query(strSql.ToString()); 
  		} 
  		 
  		/// <summary> 
  		/// 获得前几行数据 
  		/// </summary> 
  		public DataSet GetList(int Top,string strWhere,string filedOrder) 
  		{ 
  			StringBuilder strSql=new StringBuilder(); 
  			strSql.Append("select "); 
  			if(Top>0) 
  			{ 
  				strSql.Append(" top "+Top.ToString()); 
  			} 
  			strSql.Append(" * "); 
  			strSql.Append(" FROM TempStorageH "); 
  			if(strWhere.Trim()!="") 
  			{ 
  				strSql.Append(" where "+strWhere); 
  			} 
  			strSql.Append(" order by " + filedOrder); 
  			return DbHelperSQL.Query(strSql.ToString()); 
  		} 
  		/// <summary> 
  		/// 批量处理  
  		/// </summary> 
  		public int ExecuteSqlTran(List<string> ls,ref string error) 
  		{ 
  			return DbHelperSQL.ExecuteSqlTran(ls,ref   error); 
  		} 
  		 
  		/// <summary> 
  		/// 执行sql语句  
  		/// </summary> 
  		public int ExecuteSql(string sql) 
  		{ 
  			return DbHelperSQL.ExecuteSql(sql); 
  		} 
  		 
  		/// <summary> 
  		/// 执行sql语句  
  		/// </summary> 
  		public string GetSingle(string sql) 
  		{ 
  			object obj= DbHelperSQL.GetSingle(sql); 
  			 if (obj != null) 
  			 { 
  			    return obj.ToString(); 
  		     } 
  		     else 
  		        return ""; 
  		} 
  		 
  		/// <summary> 
  		/// 执行sql语句  
  		/// </summary> 
  		public DataTable  ExecuteDt(string sql) 
  		{ 
  			return DbHelperSQL.ExecuteDt(sql); 
  		} 
  		 
  		 
  		/// <summary> 
  		/// 获得记录条数 
  		/// </summary> 
  		public int GetRecordCount(string strWhere) 
  		{ 
  			StringBuilder strSql=new StringBuilder(); 
  			strSql.Append("select count(1) "); 
  			strSql.Append(" FROM TempStorageH "); 
  			if(strWhere.Trim()!="") 
  			{ 
  				strSql.Append(" where "+strWhere); 
  			} 
  		   object obj=	DbHelperSQL.GetSingle(strSql.ToString()); 
  			if(obj!=null && obj.ToString()!="") 
  			{ 
              	return Convert.ToInt32(obj); 
  			} 
  			else 
  			return 0; 
  		} 
   
      
  	} 
  
}
